package cn.sitedev.prototype.deep;

import java.util.ArrayList;
import java.util.Arrays;

/**
 * @author qchen
 * @description 原型模式测试
 * @date 2020/9/18 1:17
 */
public class PrototypeTest {
    public static void main(String[] args) {
        // 创建原型对象
        ConcretePrototype concretePrototype = new ConcretePrototype();
        concretePrototype.setAge(109);
        concretePrototype.setName("zhangsan");
        concretePrototype.setHobbies(new ArrayList(Arrays.asList("sing", "dance")));
        System.out.println("prototype: " + concretePrototype);

        // 拷贝原型对象
        ConcretePrototype cloneType = concretePrototype.deepClone();
        // 修改原型对象的浅拷贝
        cloneType.getHobbies().add("basketball");
        // 可以看到, 修改后, 创建的原型对象也发生了变化
        System.out.println("prototype: " + concretePrototype);
        System.out.println("cloneType: " + cloneType);
    }
}
